package com.lh.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.lh.commonutils.R;
import com.lh.entity.EduCourse;
import com.lh.entity.vo.CourseInfoVo;
import com.lh.entity.vo.CourseQuery;
import com.lh.entity.frontvo.CourseQueryVo;
import com.lh.service.IEduCourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author yms
 * @since 2021-06-05
 */
@RestController
@RequestMapping("/eduservice/edu-course")
//@CrossOrigin
@Api(value = "课程管理接口")
public class EduCourseController {


    @Resource
    private IEduCourseService eduCourseService;


    @ApiOperation(value = "分頁模糊查詢信息")
    @PostMapping("findAllCourse/{page}/{limit}")
    public R findAllCourse(@PathVariable Long page, @PathVariable Long limit, @RequestBody(required = false)CourseQuery courseQuery){
        Page<EduCourse> coursePage = new Page<>(page, limit);
        eduCourseService.findAllCourse(coursePage,courseQuery);
        List<EduCourse> records = coursePage.getRecords();
        long total = coursePage.getTotal();
        Map map = new HashMap<>();
        map.put("total",total);
        map.put("rows",records);

        return R.ok().data(map);
    }

    @ApiOperation(value = "根据id删除 小节，章节，描述，课程")
    @DeleteMapping("{id}")
    public R removeById(@PathVariable String id) {
      R r= eduCourseService.deleteById(id);
      return r;
    }


    @ApiOperation(value = "添加课程基本信息")
    @PostMapping("addCourseInfo")
    public R addCourseInfo(@RequestBody CourseInfoVo courseInfoVo){
        R r = eduCourseService.saveCourseInfo(courseInfoVo);
        return  r;
    }

    @ApiOperation(value = "根据课程id查询课程的基本信息")
    @GetMapping("getCourseInfo/{courseId}")
    public R getCourseInfo(@PathVariable String courseId){
        R r=eduCourseService.getCourseInfo(courseId);
        return r;
    }

    @ApiOperation(value = "修改课程的基本信息")
    @PostMapping("updateCourseInfo")
    public R updateCourseInfo(@RequestBody CourseInfoVo courseInfoVo){


        R r=eduCourseService.updateCourseInfo(courseInfoVo);
        return  r;
    }

    @ApiOperation(value = "根据课程id查询课程确定信息")
    @GetMapping("getPublishCourseInfo/{id}")
    public R getPublishCourseInfo(@PathVariable String id){

       R r =eduCourseService.getPublishCourseInfo(id);
       return r;
    }

    @ApiOperation(value = "课程最终发布")
    @GetMapping("publishCourse/{id}")
    public R publishCourse(@PathVariable String id){
       R r= eduCourseService.publishCourse(id);
       return r;
    }




}

